#include "sqlite3xx.h"
#include "sqlite3.h"

namespace sqlite3xx
{
    //typedef void sqlite3db;
    //typedef sqlite3_backup sqlite3xx_backup;
    int sqlite3xx_open(const char* filename, sqlite3db** ppDb)
    {
        return sqlite3_open(filename, (sqlite3**)ppDb);
    }
    int sqlite3xx_open16(const void* filename, sqlite3db** ppDb)
    {
        return sqlite3_open16(filename, (sqlite3**)ppDb);
    }
    int sqlite3xx_open_v2(const char* filename, sqlite3db** ppDb, int flags, const char* zVfs)
    {
        return sqlite3_open_v2(filename, (sqlite3**)ppDb, flags, zVfs);
    }

    int sqlite3xx_key(sqlite3db* db, const void* pKey, int nKey)
    {
#ifdef SQLITE_HAS_CODEC
        return sqlite3_key((sqlite3*)db, pKey, nKey);
#else
        return 0;
#endif
    }
    int sqlite3xx_key_v2(sqlite3db* db, const char* zDb, const void* pKey, int nKey) 
    {
#ifdef SQLITE_HAS_CODEC
        return sqlite3_key_v2((sqlite3*)db, zDb, pKey, nKey);
#else
        return 0;
#endif
    }
    int sqlite3xx_rekey(sqlite3db* db, const void* pKey, int nKey) 
    {
#ifdef SQLITE_HAS_CODEC
        return sqlite3_rekey((sqlite3*)db, pKey, nKey);
#else
        return 0;
#endif
    }
    int sqlite3xx_rekey_v2(sqlite3db* db, const char* zDb, const void* pKey, int nKey) 
    {
#ifdef SQLITE_HAS_CODEC
        return sqlite3_rekey_v2((sqlite3*)db, zDb, pKey, nKey);
#else
        return 0;
#endif
    }

    int sqlite3xx_close(sqlite3db* pDb)
    {
        return sqlite3_close((sqlite3*)pDb);
    }
    int sqlite3xx_close_v2(sqlite3db* pDb)
    {
        return sqlite3_close_v2((sqlite3*)pDb);
    }

    int sqlite3xx_exec(sqlite3db* pDb, const char* sql, int (*callback)(void*, int, char**, char**), void* p, char** errmsg)
    {
        return sqlite3_exec((sqlite3*)pDb, sql, callback, p, errmsg);
    }

    void sqlite3xx_free(void* p)
    {
        sqlite3_free(p);
    }

    int sqlite3xx_get_table(sqlite3db* db, const char* zSql, char*** pazResult, int* pnRow, int* pnColumn, char** pzErrmsg)
    {
        return sqlite3_get_table((sqlite3*)db, zSql, pazResult, pnRow, pnColumn, pzErrmsg);
    }

    void sqlite3xx_free_table(char** result)
    {
        sqlite3_free_table(result);
    }

    sqlite3xx_backup* sqlite3xx_backup_init(sqlite3db* pDest, const char* zDestName, sqlite3db* pSource, const char* zSourceName)
    {
        return (sqlite3xx_backup*)sqlite3_backup_init((sqlite3*)pDest, zDestName, (sqlite3*)pSource, zSourceName);
    }
    int sqlite3xx_backup_step(sqlite3xx_backup* p, int nPage)
    {
        return sqlite3_backup_step((sqlite3_backup*)p, nPage);
    }
    int sqlite3xx_backup_finish(sqlite3xx_backup* p)
    {
        return sqlite3_backup_finish((sqlite3_backup*)p);
    }

    int sqlite3xx_errcode(sqlite3db* db)
    {
        return sqlite3_errcode((sqlite3*)db);
    }
}

